package com.ruoyi.his.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.his.mapper.HisOutpatientQueueMapper;
import com.ruoyi.his.mapper.HisRegisterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.his.mapper.HisMedicalRecordMapper;
import com.ruoyi.his.domain.HisMedicalRecord;
import com.ruoyi.his.service.IHisMedicalRecordService;

/**
 * 药方Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@Service
public class HisMedicalRecordServiceImpl implements IHisMedicalRecordService 
{
    @Autowired
    private HisMedicalRecordMapper hisMedicalRecordMapper;


    @Autowired
    private HisOutpatientQueueMapper hisOutpatientQueueMapper;


    @Autowired
    private HisRegisterMapper hisRegisterMapper;


    /**
     * 新增药方
     *
     * @param hisMedicalRecord 药方
     * @return 结果
     */
    @Override
    public int insertHisMedicalRecord(HisMedicalRecord hisMedicalRecord)
    {


        String CFID = UUID.randomUUID().toString().replace("-", "");

        hisMedicalRecord.setCreateDatetime(DateUtils.getTime());
        hisMedicalRecord.setId("CF_"+CFID);

        int i = hisMedicalRecordMapper.insertHisMedicalRecord(hisMedicalRecord);

        if(1==i){//门诊结束

            //TODO

            String registerId = hisMedicalRecord.getRegisterId();
            // 门诊结束,修改病人挂号收费表信息  register_status = 0, treatment_status = 1, charge_status=1
            //  1.未挂号    2.就诊结束    3.已付款
            hisRegisterMapper.updateHisRegisterByPatientId(hisMedicalRecord.getRegisterId());









        }

        return i;
    }















    /**
     * 查询药方
     * 
     * @param id 药方主键
     * @return 药方
     */
    @Override
    public HisMedicalRecord selectHisMedicalRecordById(String id)
    {
        return hisMedicalRecordMapper.selectHisMedicalRecordById(id);
    }

    /**
     * 查询药方列表
     * 
     * @param hisMedicalRecord 药方
     * @return 药方
     */
    @Override
    public List<HisMedicalRecord> selectHisMedicalRecordList(HisMedicalRecord hisMedicalRecord)
    {
        return hisMedicalRecordMapper.selectHisMedicalRecordList(hisMedicalRecord);
    }



    /**
     * 修改药方
     * 
     * @param hisMedicalRecord 药方
     * @return 结果
     */
    @Override
    public int updateHisMedicalRecord(HisMedicalRecord hisMedicalRecord)
    {
        return hisMedicalRecordMapper.updateHisMedicalRecord(hisMedicalRecord);
    }

    /**
     * 批量删除药方
     * 
     * @param ids 需要删除的药方主键
     * @return 结果
     */
    @Override
    public int deleteHisMedicalRecordByIds(String[] ids)
    {
        return hisMedicalRecordMapper.deleteHisMedicalRecordByIds(ids);
    }

    /**
     * 删除药方信息
     * 
     * @param id 药方主键
     * @return 结果
     */
    @Override
    public int deleteHisMedicalRecordById(String id)
    {
        return hisMedicalRecordMapper.deleteHisMedicalRecordById(id);
    }
}
